/*
 * Copyright (C) 2008 Jens Meiß
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package com.googlecode.hmvc4gwt.example.hmvcblog.server.domain.user;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

import com.googlecode.hmvc4gwt.example.hmvcblog.server.domain.IIdentifyable;
import com.googlecode.hmvc4gwt.example.hmvcblog.server.domain.blog.Blog;



/**
 * Data Transfer Object for the User-Data
 * 
 * @author jens.meiss
 */
@Entity
@NamedQueries( {
		@NamedQuery(name = "User.findByLogin", query = "SELECT user FROM User user WHERE user.login = ?1"),
		@NamedQuery(name = "User.getAllUsers", query = "FROM User user"),
		@NamedQuery(name = "User.countAllUsers", query = "SELECT count(*) FROM User user"),
		@NamedQuery(name = "User.findBySessionId", query = "SELECT user FROM User user WHERE user.sessionId = ?1")
})
public class User implements IIdentifyable {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * the email address of the user
	 */
	private String email;

	/**
	 * first name of the user
	 */
	private String foreName;

	/**
	 * contains the user-id
	 */
	private int id;

	/**
	 * a list of all Blogs of the user
	 */
	private List<Blog> listBlog;

	/**
	 * the current SessionId of the user
	 */
	private Long sessionId;

	/**
	 * user login-name
	 */
	private String login;

	/**
	 * password of the users login-name
	 */
	private String password;

	/**
	 * last name of the user
	 */
	private String sureName;
	
	/**
	 * @return the email
	 */
	@Column(unique=true, nullable=false)
	public String getEmail() {
		return email;
	}
	
	/**
	 * @return the firstName
	 */
	public String getForeName() {
		return foreName;
	}
	
	/**
	 * @return the Database id of the User
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return id;
	}

	@OneToMany(cascade=CascadeType.REMOVE)
	public List<Blog> getListBlog() {
		return listBlog;
	}

	/**
	 * @return the login name of the user
	 */
	@Column(nullable=false, unique=true)
	public String getLogin() {
		return login;
	}

	/**
	 * @return the password
	 */
	@Column(nullable=false)
	public String getPassword() {
		return password;
	}

	@Column(unique=true)
	public Long getSessionId() {
		return sessionId;
	}

	/**
	 * @return the lastName
	 */
	public String getSureName() {
		return sureName;
	}

	/**
	 * @param email
	 *            the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @param firstName
	 *            the firstName to set
	 */
	public void setForeName(String foreName) {
		this.foreName = foreName;
	}

	/**
	 * @param id
	 */
	public void setId(int id) {
		this.id = id;
	}

	public void setListBlog(List<Blog> listBlog) {
		this.listBlog = listBlog;
	}

	/**
	 * @param login
	 *            the login to set
	 */
	public void setLogin(String login) {
		this.login = login;
	}

	/**
	 * @param password
	 *            the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	public void setSessionId(Long sessionId) {
		this.sessionId = sessionId;
	}

	/**
	 * @param lastName
	 *            the lastName to set
	 */
	public void setSureName(String sureName) {
		this.sureName = sureName;
	}

}
